<?php
	$protectid="14"; 
	include("../protect.php");
	
	//include_once("../../fckeditor/fckeditor.php");
	include_once("../../config.inc.php");
	
	$strID = $_GET['id'];	
	$strAct = (empty($_GET['act'])) ? "add" : $_GET['act'];
	$strOperation = ( $strAct == "add" ) ? "添加" : "修改";
	
	include_once(CFG_LIB_DIR.'mysqldb.inc.php');		
	$objDb = new mysqldb();
	
	$strSQL = "SELECT * FROM `".con_strPREFIX."sys_products` WHERE SysProductsID = ".$strID." LIMIT 1";
	$objDb->query($strSQL);
	$tmpResult = $objDb->get_data();
	$ProResult = $tmpResult[0];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $strOperation; ?>产品</title>

<script type="text/javascript" src="../../ueditor/editor_config.js"></script>
<script type="text/javascript" src="../../ueditor/editor_all.js"></script>
<?php include_once("../common/files.php"); ?>

<script type="text/javascript">
	function validForm()
	{
		var arrNotBlankElement = new Array("infoTitleTr", "sortTr", "topTr", "extractTr", "publishDateTr");
		if(validNotBlank(arrNotBlankElement) == false)
			return false;
			
		var arrDateElementID = new Array("ValidDate");
		if(validDate(arrDateElementID) == false)
			return false;
			
		var arrNumElementID = new Array("SortNum", "TopNum", "ExtractNum");
		if(validSortNum(arrNumElementID) == false)
			return false;
			
		return true;
	}
	
</script>
</head>

<body id="main" >
<table summary="" id="pagehead" cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr>
		<td><h1>批量上传产品</h1></td>
		<td class="actions">
			<table summary="" cellpadding="0" cellspacing="0" border="0" align="right">
				<tr>
          <td ><a href="#" ><?php echo $strOperation; ?>产品</a></td>
		  	<td  class="active"><a href="piaddproduct.php" >批量上传产品</a></td>
					<td ><a href="#" onclick="return ConfirmCloseWinow('');">关闭</a></td>
				</tr>
			</table>
		</td>
	</tr>
</table>


<?php


if(@$_FILES['fileField']){
	$file_name = $_FILES['fileField']['tmp_name'];
	$fp = fopen($file_name,'r');
	while(!feof($fp)){
		$arr[] = fgets($fp,4096);
	} 
	fclose($fp);
	
	$num = 50;   //每组集成包包含的代码
	if($arr){
		for($i=0;$i<ceil(count($arr)/$num);$i++){
			$slicearr[] = array_slice($arr, $i * $num ,$num);
		}
	}
	
	if($slicearr){
	   foreach($slicearr as $key=>$value){
	       $content = implode($value,",");
		   $name = date("批量上传组件ymdhis",time()).$key;
		   $strSQL = "insert  into `hy_b_sys_products`(`SysProductsID`,`CateID`,`BrandID`,`ProductName`,`SubName`,`Price`,`Postage`,`Express`,`Ems`,`Unit`,`Material`,`Size`,`Color`,`FirstPhoto`,`Photos`,`Files`,`Note`,`Tag`,`RelationID`,`PublishDate`,`ModifiedDate`,`ValidDate`,`SortNum`,`Lang`,`TopNum`,`ExtractNum`,`IsLock`,`Clicks`,`CreationUserID`,`ModifiedUserID`,`active`,`Photos1`,`Price2`,`Price3`,`Ren`,`Ren2`,`Ren3`,`StartDate`,`DingJin`,`Photos2`,`Photos3`,`Photos4`,`Photos5`,`Photos6`,`yuanjia`,`CityID`) values ('','11010','','rrer','".$name."',0,'0.00','0.00','0.00','','','','','','','','".$content."',0,'','".time()."','".time()."','".time()."',9999,'cn',9999,9999,0,0,2,2,0,'20130728043727.jpg',0,0,0,0,0,'',0,'','','','','','rerer',0);";
		   
		   $msg = $objDb->query($strSQL);
	   }
	   if($msg) echo "<script>alert('批量上传完成！');location.href='index.php';</script>"; 
	   else    echo "<script>alert('批量上传失败！');location.href='index.php'; </script>"; 
	}
	
	
 
}



?>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="">
  <label for="fileField">批量上传产品</label>
  <input type="file" name="fileField" id="fileField" />
  <input type="submit" name="button" id="button" value="上传" /> <br/>
	   注意：格式为*.txt,号码一行为一个.<br/>50个为一组
</form>


<br>
<?php include "../bottom.php"; ?>
</div>
</body>
</html>
<?php $objDb->close(); ?>